﻿CREATE PROCEDURE [dbo].[Note_Delete]
	@noteId BIGINT,
	@userId	UNIQUEIDENTIFIER,
	@textId BIGINT
AS
BEGIN
	IF EXISTS (SELECT * FROM [dbo].[mark_Share_Text] WHERE [NoteId] = @noteId)
	BEGIN
		UPDATE [dbo].[mark_Note]
		SET	[IsDeleted] = 1
		WHERE [NoteId] = @noteId AND [UserId] = @userId AND [TextId] = @textId
	END
	ELSE
	BEGIN
		DELETE FROM [dbo].[mark_Note]
		WHERE [NoteId] = @noteId AND [UserId] = @userId AND [TextId] = @textId
	END

	DECLARE @resultCount INT =  @@rowcount

	SELECT @resultCount AS [Count]
END